import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/sift/index/index.dart';
import 'package:nft_shop/sift/page/sift_page.dart';
import 'package:nft_shop/splash.dart';
import 'package:nft_shop/util/handle_error_utils.dart';
import 'package:nft_shop/util/route_observer.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

void main () async {

  Global.init(() {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
        .then((_) {
      runApp(MyApp());
    });
  });
}

//Bus 初始化
EventBus eventBus = EventBus();

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      hideFooterWhenNotFull: true, //列表数据不满一页,不触发加载更多
      child: GetMaterialApp(
        title: Global.AppName,
        // showPerformanceOverlay: true, //显示性能标签
        debugShowCheckedModeBanner: false, // 去除右上角debug的标签
        // checkerboardRasterCacheImages: true,
        // showSemanticsDebugger: true, // 显示语义视图
        // checkerboardOffscreenLayers: true, // 检查离屏渲染
        enableLog: true,
        defaultTransition: Transition.rightToLeft,
        theme: Global().getTheme(),
        home: SplashPage(),
        routes: {
          Constant.routeSplash: (ctx) => SplashPage(),
          Constant.routeHome: (ctx) => IndexPage(),
        },
        navigatorObservers: [RouteUtils.routeObserver],
        builder: (BuildContext context, Widget? child) {
          /// 仅针对安卓
          // if (Device.isAndroid) {
          //   /// 切换深色模式会触发此方法，这里设置导航栏颜色
          //   ThemeUtils.setSystemNavigationBar(provider.getThemeMode());
          // }
          EasyLoading.init();
          /// 保证文字大小不受手机系统设置影响 https://www.kikt.top/posts/flutter/layout/dynamic-text/
          return FlutterEasyLoading(
            child: MediaQuery(
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: child!,
            ),
          );
        },
      ),
    );
  }
}

